package view;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;


/*
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
 * class GUIServer - a GUI of install the server
 */
public class GUIServer extends org.eclipse.swt.widgets.Composite {

	{
		//Register as a resource user - SWTResourceManager will
		//handle the obtaining and disposing of resources
		SWTResourceManager.registerResourceUser(this);
	}
	

	private Label details;
	private Label title;
	private Button OkButton;
	private static String sqlUser=null;
	private static String sqlPass=null;
	private static Shell shell;
	private Label ImgCloseLable;
	private Label sqlUserLab;
	private Label sqlPasswordLab;
	private Text sqlPassTxt;
	private Text sqlUserTxt;
	
	
	/**
	 * constructor
	 * @param parent
	 * @param style
	 */
	public GUIServer(Composite parent, int style){
		super(parent, style);
		initGUI();
	}

	/*
	* Initializes the GUI.
	*/
	private void initGUI() {
		try{

			this.setSize(497, 246);
			this.setBackground(SWTResourceManager.getColor(36, 209, 219));
			FormLayout thisLayout = new FormLayout();
			this.setLayout(thisLayout);
			{
				FormData ImgCloseLableLData = new FormData();
				ImgCloseLableLData.left =  new FormAttachment(0, 1000, 353);
				ImgCloseLableLData.top =  new FormAttachment(0, 1000, 78);
				ImgCloseLableLData.width = 132;
				ImgCloseLableLData.height = 104;
				ImgCloseLable = new Label(this, SWT.NONE);
				ImgCloseLable.setLayoutData(ImgCloseLableLData);
				ImgCloseLable.setBackgroundImage(SWTResourceManager.getImage("images/Picture1.png"));
			}
			{
				sqlPasswordLab = new Label(this, SWT.NONE);
				FormData sqlPasswordLabLData = new FormData();
				sqlPasswordLabLData.left =  new FormAttachment(0, 1000, 13);
				sqlPasswordLabLData.top =  new FormAttachment(0, 1000, 141);
				sqlPasswordLabLData.width = 126;
				sqlPasswordLabLData.height = 20;
				sqlPasswordLab.setLayoutData(sqlPasswordLabLData);
				sqlPasswordLab.setText("SQL password:");
				sqlPasswordLab.setFont(SWTResourceManager.getFont("Showcard Gothic", 11, 0, false, false));
				sqlPasswordLab.setBackground(SWTResourceManager.getColor(36, 209, 219));
			}
			{
				sqlUserLab = new Label(this, SWT.NONE);
				FormData sqlUserLabLData = new FormData();
				sqlUserLabLData.left =  new FormAttachment(0, 1000, 31);
				sqlUserLabLData.top =  new FormAttachment(0, 1000, 98);
				sqlUserLabLData.width = 80;
				sqlUserLabLData.height = 21;
				sqlUserLab.setLayoutData(sqlUserLabLData);
				sqlUserLab.setText("SQL user:");
				sqlUserLab.setFont(SWTResourceManager.getFont("Showcard Gothic", 11, 0, false, false));
				sqlUserLab.setBackground(SWTResourceManager.getColor(36, 209, 219));
			}
			{
				sqlPassTxt = new Text(this, SWT.NONE);
				FormData sqlPassLData = new FormData();
				sqlPassLData.left =  new FormAttachment(0, 1000, 145);
				sqlPassLData.top =  new FormAttachment(0, 1000, 141);
				sqlPassLData.width = 190;
				sqlPassLData.height = 20;
				sqlPassTxt.setLayoutData(sqlPassLData);
			}
			{
				FormData sqlUserLData = new FormData();
				sqlUserLData.left =  new FormAttachment(0, 1000, 145);
				sqlUserLData.top =  new FormAttachment(0, 1000, 98);
				sqlUserLData.width = 190;
				sqlUserLData.height = 21;
				sqlUserTxt = new Text(this, SWT.NONE);
				sqlUserTxt.setLayoutData(sqlUserLData);
			}
			{
				FormData detailsLData = new FormData();
				detailsLData.left =  new FormAttachment(0, 1000, 152);
				detailsLData.top =  new FormAttachment(0, 1000, 51);
				detailsLData.width = 177;
				detailsLData.height = 21;
				details = new Label(this, SWT.NONE);
				details.setLayoutData(detailsLData);
				details.setText("Please complete the fields");
				details.setFont(SWTResourceManager.getFont("Segoe Print", 10, 0, false, false));
				details.setBackground(SWTResourceManager.getColor(36, 209, 219));
			}
			{
				title = new Label(this, SWT.NONE);
				FormData titleLData = new FormData();
				titleLData.left =  new FormAttachment(0, 1000, 71);
				titleLData.top =  new FormAttachment(0, 1000, 20);
				titleLData.width = 360;
				titleLData.height = 35;
				title.setLayoutData(titleLData);
				title.setText("Dropbox Server Initialization ! =)");
				title.setFont(SWTResourceManager.getFont("Segoe Script", 14, 0, false, false));
				title.setBackground(SWTResourceManager.getColor(36, 209, 219));
			}
			{
				OkButton = new Button(this, SWT.PUSH | SWT.CENTER);
				FormData OkButtonLData = new FormData();
				OkButtonLData.left =  new FormAttachment(0, 1000, 186);
				OkButtonLData.top =  new FormAttachment(0, 1000, 193);
				OkButtonLData.width = 107;
				OkButtonLData.height = 30;
				OkButton.setLayoutData(OkButtonLData);
				OkButton.setText("Apply");
				OkButton.setFont(SWTResourceManager.getFont("Showcard Gothic", 12, 2, false, false));
				OkButton.setEnabled(true);
				OkButton.setBackground(SWTResourceManager.getColor(36, 209, 219));
				OkButton.setGrayed(true);

				//when click on the "apply" button
				OkButton.addSelectionListener(new SelectionListener() {
					
					@Override
					public void widgetSelected(SelectionEvent arg0) {
						
						sqlUser=sqlUserTxt.getText();
						sqlPass=sqlPassTxt.getText();

						shell.close();						
						
					}
					
					@Override
					public void widgetDefaultSelected(SelectionEvent arg0) {
						// TODO Auto-generated method stub
						
					}
				});
			
					
			}	
		

			this.layout();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * start the GUI of installing the server
	 */
	public static void GUIServerMain (){
		System.out.println("GUIMAIN");
		Display display = Display.getDefault();
		shell = new Shell(display,SWT.NO_REDRAW_RESIZE | SWT.DIALOG_TRIM | SWT.MIN);
		GUIServer inst = new GUIServer(shell, SWT.NULL);
		Point size = inst.getSize();
		shell.setLayout(new FillLayout());
		shell.setText("DropBox");
		shell.layout();
		if(size.x == 0 && size.y == 0) {
			inst.pack();
			shell.pack();
		} else {
			Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
			shell.setSize(shellBounds.width, shellBounds.height);
		}
	
		System.out.println("OPEN SHELL");
		shell.open();
		System.out.println("AFTER----OPEN SHELL");
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}
	

	/**
	 * @return the sql user that the user insert in the GUI
	 */
	public static String getSqlUser() {
		return sqlUser;
	}

	/**
	 * @return the sql password that the user insert in the GUI
	 */
	public static String getSqlPass() {
		return sqlPass;
	}

		
}


	
	


